#! /bin/sh
# PCP QA Test No. 024
# juggling with contexts, including the default one
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard filters
. ./common.product
. ./common.filter
. ./common.check

PMCD_CONNECT_TIMEOUT=120
PMCD_REQUEST_TIMEOUT=120
export PMCD_CONNECT_TIMEOUT PMCD_REQUEST_TIMEOUT

_filter()
{
    # unfortunatley, -Dcontext maps to an internal debug flag for some PMDAs
    # for nodes et al
    # filter for __pmDecodeXtendError diag because datum is not
    # invariant
    #
    sed \
	-e '/using .* kmem interface/d' \
	-e 's/localhost/<&>/' \
	-e "s/`hostname`\([):]\)/<localhost>\1/" \
	-e "s/$remote\([):]\)/<remotehost>\1/" \
	-e 's/fd=[0-9][0-9]*/fd=<n>/g' \
	-e 's/features=[0-9][0-9]*/features=<n>/g' \
	-e 's/port=[0-9][0-9]*/port=<n>/g' \
	-e 's/handle=0x0/handle=(nil)/' \
	-e '/ Debug: reload_nodes: /d'\
	-e '/ Debug: reload_nodeinfo: /d'\
	-e '/ Debug: node_init: /d' \
	-e '/ Debug: reload_hubs: /d' \
	-e '/ Debug: handle_entry: /d' \
	-e '/^__pmDecodeXtendError: got error PDU/s/datum=[0-9][0-9]*/datum=DATA/' \
	-e '/^pmWhichContext() -> /d' \
	-e '/__pmSendCreds: #0/s/= 201/= 1020000/' \
	-e '/^__pmDataIPC: /d' \
	-e '/^__pmSetSocketIPC: fd/d' \
	-e '/^IPC table fd/d' \
	-e '/^__pmSetDataIPC/{
N
d
}' \
	-e 's/ [0-9][0-9]*(?)//g' \
	-e "s;$PCP_PMDAS_DIR;\$PCP_PMDAS_DIR;" \
	-e "s/$DSO_SUFFIX\([ ,]\)/\$DSO_SUFFIX\1/" \
        -e '/IPC table/{
s/ [0-9][0-9]*(?)//g
s/ [0-9][0-9]*(2)/ <n>(2)/g
s/ [0-9][0-9]*(2,1)/ <n>(2,1)/g
}' \
	-e 's/^\[[0-9][0-9]*]/[N]/' \
	-e "s;\([/_]\)linux/;/\1OS/;" \
	-e "s;\([/_]\)darwin/;/\1OS/;" \
	-e "s;\([/_]\)solaris/;/\1OS/;" \
	-e "s;\([/_]\)windows/;/\1OS/;" \
	-e "/jbd2/d" \
	-e "/pmproxy_init/d" \
	-e '/^0*x*[0-9a-f][0-9a-f]* /{
s//ADDR /
s/\[[0-9][0-9]*]/[N]/
s;=[0-9].*/OS/.*;=N name=OS_PMDA, ...;
}' \
	-e '/^\[N] .*\/OS\//s/.*/[N] domain=N, name=OS_PMDA, .../' \
	-e '/^__pmLocalPMDA(.*\/OS\//{
s/name=.*/name=OS_PMDA, ...)/
s/domain=[0-9][0-9]*/domain=N/
}' \
	-e '/__pmConnect(fd=<n>(nsprFd=/d' \
	-e '/^NotifyEndLocalContext:/{
/pmda_linux/d
}' \
	# end

}

# some non-derminism after the build_dsotable lines for __pmSetSocketIPC and
# IPC table, hence skip these in this context
#
_filter2()
{
    $PCP_AWK_PROG '
/build_dsotab:/			{ strip=1; print; print "<stripped lines>"; next }
strip == 1 && /pmSetSocketIPC/	{ next }
strip == 1 && /IPC table/	{ next }
strip == 1 && /pmNewContext/	{ strip=0 }
strip == 1			{ print >"'$tmp.tmp'"; next }
				{ print }'
}

trap "$sudo rm -f $tmp.*; exit" 0 1 2 3 15

remote=`./getpmcdhosts -L -n 1 -a sample 2>$tmp.out`
[ -z "$remote" ] && _notrun `cat $tmp.out`

# real QA test starts here
echo "=== expected to pass ==="
src/chkctx2 -Dcontext 2>&1 | _filter
echo ""
src/chkctx2 -Dcontext -h localhost 2>&1 | _filter
echo ""
src/chkctx2 -Dcontext -h `hostname` 2>&1 | _filter
echo ""
src/chkctx2 -Dcontext -h $remote 2>&1 | _filter
echo ""

PCP_LITE_SAMPLE=yes
export PCP_LITE_SAMPLE

echo | tee -a $seq_full
echo "=== try CONTEXT_LOCAL ===" | tee -a $seq_full
$sudo_local_ctx src/chkctx2_lite -Dcontext -L 2>&1 \
| tee -a $seq_full \
| _filter \
| _filter2 \
| _filter_pmcd_log

echo
echo "sorted stripped lines ..."
LC_COLLATE=POSIX sort $tmp.tmp | uniq

